import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { FormatResponseInterceptor } from './common/interceptors/transform.interceptor';
import { InvokeRecordInterceptor } from './invoke-record.interceptor';
import { UnloginFilter } from './unlogin.filter';
import { CustomExceptionFilter } from './custom-exception.filter';
import * as session from 'express-session'
import { VersioningType } from '@nestjs/common';

const PORT = process.env.SERVE_PORT || 3000
async function bootstrap() {
  const app = await NestFactory.create(AppModule,{cors:{
    credentials:true,
    origin:"http://localhost:5173"
  },});
  // console.log('服务端口',process.env.SERVE_PORT)
  app.enableVersioning({
    type: VersioningType.URI
  })
  // app.useGlobalFilters(new HttpExceptionFilter)
  //注册全局返回参数格式处理
  app.useGlobalInterceptors(new FormatResponseInterceptor());
  // 打印一些请求信息
  app.useGlobalInterceptors(new InvokeRecordInterceptor());
  //全局异常格式处理
  app.useGlobalFilters(new UnloginFilter())
  app.useGlobalFilters(new CustomExceptionFilter())
  app.use(session({ secret: "qiuhan",name: 'suuid', rolling: false, saveUninitialized: false ,cookie: {
    // 过期时间, 单位毫秒。这里设置10分钟
    maxAge: 600000,
    // cookie是否签名
    signed: false,
  }}))
  await app.listen(PORT);
}
bootstrap();
